﻿/*========================== 
 * @author 郑金泉
 * @desc List实用工具
 * ========================= */
using System;
using System.Collections.Generic;
using System.Text;

namespace Obsidian.Utils
{

    /// <summary>
    /// List实用工具
    /// </summary>
    public class ListUtil
    {

        /// <summary>
        /// 转化为List
        /// </summary>
        /// <param name="arrInt">int数组</param>
        /// <returns></returns>
        public static List<int> ToIntList(int[] arrInt)
        {
            List<int> intList = new List<int>();
            foreach (int i in arrInt)
                intList.Add(i);
            return intList;
        }

        /// <summary>
        /// 转化为intList
        /// </summary>
        /// <param name="objList"></param>
        /// <returns></returns>
        public static List<int> ToIntList(List<object> objList)
        {
            List<int> intList = new List<int>();
            foreach (object o in objList)
                intList.Add(Convert.ToInt32(o));
            return intList;
        }

        /// <summary>
        /// 转化为int数组
        /// </summary>
        /// <param name="objList"></param>
        /// <returns></returns>
        public static int[] ToIntArray(List<object> objList)
        {
            int[] arrID = new int[objList.Count];
            for (int i = 0; i < objList.Count; i++)
                arrID[i] = Convert.ToInt32(objList[i]);
            return arrID;
        }


        /// <summary>
        /// 转化为Object数组
        /// </summary>
        /// <param name="intList">List</param>
        /// <returns></returns>
        public static object[] GetObjectArray(List<int> intList)
        {
            object[] arrObject = new object[intList.Count];
            for (int i = 0; i < intList.Count; i++)
                arrObject[i] = intList[i];
            return arrObject;
        }

    }
}
